import { createApp } from 'vue';
import './style.css';
import App from './App.vue';
import router from './router/index';
import store from './store/index';

import TIM from 'tim-js-sdk';
import TIMUploadPlugin from 'tim-upload-plugin';
// 初始化样式文件
import './assets/less/reset.less';
import './assets/less/common.less';
// 按需引入elmentPlus框架
import { ElConfigProvider, ElButton, ElInfiniteScroll } from 'element-plus'
import 'element-plus/dist/index.css'
// 按需引入vant框架
import { NavBar, Toast, Dialog, Notify, ImagePreview, ConfigProvider, TabbarItem, Tabbar, Sticky, Swipe, SwipeItem } from 'vant';
import 'vant/lib/index.css';
const app = createApp(App);
app.use(ElConfigProvider).use(ElButton).use(ElInfiniteScroll)
app.use(Toast).use(NavBar).use(Dialog).use(Notify).use(ImagePreview).use(Swipe).use(SwipeItem).use(Sticky).use(ConfigProvider).use(TabbarItem).use(Tabbar);
app.use(router);
app.use(store);


let options = {
	SDKAppID: 1400714569
};

let tim = TIM.create(options); // SDK 实例通常用 tim 表示

tim.setLogLevel(0);

tim.registerPlugin({ 'tim-upload-plugin': TIMUploadPlugin });
app.config.globalProperties.tim = tim;
app.config.globalProperties.TIM = TIM;
app.config.globalProperties.productionTip = false
console.log('tim==>', tim);

app.config.globalProperties.$filters = {
	formatTime(time: any) {
		let netConnectTime = parseInt((time * 1000).toString());//网络连接时间
		let currentTime = parseInt((new Date().getTime()).toString());//当前时间
		let hasUseTime = parseInt((((currentTime - netConnectTime) / 1000).toString()));
		console.log(netConnectTime, currentTime, hasUseTime);

		let returnTime = '';
		// 1 时 = 3600秒 1分 = 60秒
		if (hasUseTime < 60) {
			if (hasUseTime < 0) {
				returnTime = "0秒以前"
			} else {
				returnTime = hasUseTime + "秒以前"
			}
			return returnTime;

		} else if (hasUseTime >= 60 && hasUseTime <= 3600) {
			if (hasUseTime > 300) {  //大于5分钟标红
				returnTime = parseInt((hasUseTime / 60).toString()) + "分钟前"
				return returnTime;
			} else {
				returnTime = hasUseTime / 60 + "分钟前"
				return returnTime;
			}
		} else if (hasUseTime > 3600 && hasUseTime <= 3600 * 24) {
			let h = parseInt((hasUseTime / 3600).toString());
			returnTime = h + "小时"
			return returnTime;

		} else if (hasUseTime > 3600 * 24) {
			let day = parseInt((hasUseTime / (24 * 3600)).toString());
			/*  let day =hasUseTime/(3600*24)); //天数
				let hour =hasUseTime % (60*24));   // hasUseTime % 3600 求余数分钟
				let minute =  hasUseTime % (3600*24)*/
			returnTime = day + "天";
			return returnTime;
		}
	}

}


app.mount('#app');

